1   // Copyright 2007, 2008, 2009 The Apache Software Foundation
2   //
3   // Licensed under the Apache License, Version 2.0 (the "License");
4   // you may not use this file except in compliance with the License.
5   // You may obtain a copy of the License at
6   //
7   //     http://www.apache.org/licenses/LICENSE-2.0
8   //
9   // Unless required by applicable law or agreed to in writing, software
10  // distributed under the License is distributed on an "AS IS" BASIS,
11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  // See the License for the specific language governing permissions and
13  // limitations under the License.
14  
15  package org.apache.tapestry5.root;
16  
17  import org.apache.tapestry5.MarkupUtils;
18  import org.testng.Assert;
19  import org.testng.annotations.DataProvider;
20  import org.testng.annotations.Test;
21  
22  import java.util.Arrays;
23  import java.util.List;
24  
25  public class MarkupUtilsTest extends Assert
26  {
27      @Test(dataProvider = "string_quoting_input")
28      public void string_quoting(String input, String expected)
29      {
30          assertEquals(MarkupUtils.quote(input), expected);
31      }
32  
33      @DataProvider
34      public Object[][] string_quoting_input()
35      {
36          return new Object[][]
37                  {
38                          { "Suzy said: \"It's not the proper time\".",
39                                  "'Suzy said: \\\"It\\'s not the proper time\\\".'" },
40                          { "regexp: \\d{4}", "'regexp: \\\\d{4}'" },
41  
42                  };
43      }
44  
45      @Test(dataProvider = "join_input")
46      public void join_array(String[] inputs, String expected)
47      {
48          assertEquals(MarkupUtils.join(inputs), expected);
49      }
50  
51      @Test(dataProvider = "join_input")
52      public void join_list(String[] inputs, String expected)
53      {
54          List<String> list = Arrays.asList(inputs);
55  
56          assertEquals(MarkupUtils.join(list), expected);
57      }
58  
59      @DataProvider
60      public Object[][] join_input()
61      {
62          return new Object[][]
63                  {
64                          { new String[0], "" },
65                          { new String[]
66                                  { "fred" }, "fred" },
67                          { new String[]
68                                  { "fred", "barney", "wilma" }, "barney fred wilma" } };
69      }
70  
71  
72  }